package ie.dkit.java3Demulation.objects3d;

import java.util.ArrayList;
import java.util.Collection;

import ie.dkit.java3Demulation.drawer.Line3DDrawable;
import ie.dkit.java3Demulation.transforming.Transformable;

public class Parallelogram implements Transformable, Line3DDrawable {

	private Rectangle m_Rectancle1, m_Rectancle2;

	private Point3D m_Center, m_RotationPoint;

	private String name;

	private Line3D line1, line2, line3, line4;

	// TODO: jonathan insert usable default values.
	public Parallelogram() {
		this(new Rectangle(), new Rectangle());
	}

	public Parallelogram(Rectangle r1, Rectangle r2) {
		m_Rectancle1 = r1;
		m_Rectancle2 = r2;
		double xc = (m_Rectancle1.getCentre().getX() + m_Rectancle2.getCentre()
				.getX()) / 2;
		double yc = (m_Rectancle1.getCentre().getY() + m_Rectancle2.getCentre()
				.getY()) / 2;
		double zc = (m_Rectancle1.getCentre().getZ() + m_Rectancle2.getCentre()
				.getZ()) / 2;
		Point3D p = new Point3D(xc, yc, zc);
		m_Center = p;
		line1 = new Line3D(m_Rectancle1.getPoint1(), m_Rectancle2.getPoint1());
		line2 = new Line3D(m_Rectancle1.getLeftBottom(), m_Rectancle2
				.getLeftBottom());
		line3 = new Line3D(m_Rectancle1.getRightBottom(), m_Rectancle2
				.getRightBottom());
		line4 = new Line3D(m_Rectancle1.getM_Point4(), m_Rectancle2
				.getM_Point4());
	}

	public Point3D getCentre() {
		return m_Center;
	}

	public Rectangle getR1() {
		return m_Rectancle1;
	}

	public Rectangle getR2() {
		return m_Rectancle2;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ie.dkit.java3Demulation.transforming.Transformable#getPoints()
	 */
	public Collection<Point3D> getPoints() {
		Collection<Point3D> returnValue = new ArrayList<Point3D>();
		returnValue.addAll(m_Rectancle1.getPoints());
		returnValue.addAll(m_Rectancle2.getPoints());
		return returnValue;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ie.dkit.java3Demulation.transforming.Transformable#getRotationPoint()
	 */
	public Point3D getRotationPoint() {
		return m_RotationPoint;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ie.dkit.java3Demulation.transforming.Transformable#setRotationPoint(ie.dkit.java3Demulation.objects3d.Point3D)
	 */
	public void setRotationPoint(Point3D point3D) {
		m_RotationPoint = point3D;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ie.dkit.java3Demulation.objects.GraphicsObject#getName()
	 */
	public String getName() {
		return name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ie.dkit.java3Demulation.objects.GraphicsObject#setName(java.lang.String)
	 */
	public void setName(String name) {
		this.name = name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ie.dkit.java3Demulation.linedrawing.Drawable#getLines()
	 */
	public Collection<Line3D> getLines() {
		Collection<Line3D> returnValue = new ArrayList<Line3D>();
		returnValue.add(line1);
		returnValue.add(line2);
		returnValue.add(line3);
		returnValue.add(line4);
		return returnValue;
	}
}
